home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / emula / arosdv19.lha / AROS / exec / attemptsemaphore.c < prev    next >
C/C++ Source or Header  |  1996-10-24  |  2KB  |  90 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: attemptsemaphore.c,v 1.5 1996/10/24 15:50:45 aros Exp $
  4.     $Log: attemptsemaphore.c,v $
  5.     Revision 1.5  1996/10/24 15:50:45  aros
  6.     Use the official AROS macros over the __AROS versions.
  7.  
  8.     Revision 1.4  1996/08/13 13:55:58  digulla
  9.     Replaced AROS_LA by AROS_LHA
  10.     Replaced some AROS_LH*I by AROS_LH*
  11.     Sorted and added includes
  12.  
  13.     Revision 1.3  1996/08/01 17:41:05  digulla
  14.     Added standard header for all files
  15.  
  16.     Desc:
  17.     Lang: english
  18. */
  19. #include "exec_intern.h"
  20.  
  21. /*****************************************************************************
  22.  
  23.     NAME */
  24.     #include <exec/semaphores.h>
  25.     #include <clib/exec_protos.h>
  26.  
  27.     AROS_LH1(ULONG, AttemptSemaphore,
  28.  
  29. /*  SYNOPSIS */
  30.     AROS_LHA(struct SignalSemaphore *, sigSem, A0),
  31.  
  32. /*  LOCATION */
  33.     struct ExecBase *, SysBase, 96, Exec)
  34.  
  35. /*  FUNCTION
  36.     Tries to get an exclusive lock on a signal semaphore. If the semaphore
  37.     is already in use by another task this function does not wait but
  38.     return false instead.
  39.  
  40.     INPUTS
  41.     sigSem - Pointer so semaphore structure.
  42.  
  43.     RESULT
  44.     TRUE if the semaphore could be obtained, FALSE otherwise.
  45.  
  46.     NOTES
  47.     The lock must be freed with ReleaseSemaphore().
  48.  
  49.     EXAMPLE
  50.  
  51.     BUGS
  52.  
  53.     SEE ALSO
  54.     ReleaseSemaphore()
  55.  
  56.     INTERNALS
  57.  
  58.     HISTORY
  59.     29-10-95    digulla automatically created from
  60.                 exec_lib.fd and clib/exec_protos.h
  61.     21-01-96    fleischer implementation
  62.  
  63. *****************************************************************************/
  64. {
  65.     AROS_LIBFUNC_INIT
  66.     AROS_LIBBASE_EXT_DECL(struct ExecBase *,SysBase)
  67.  
  68.     LONG ret=0;
  69.  
  70.     /* Arbitrate for semaphore nesting count and owner fields */
  71.     Forbid();
  72.  
  73.     /* If the semaphore is free or the user is the current task */
  74.     if(!sigSem->ss_NestCount||sigSem->ss_Owner==SysBase->ThisTask)
  75.     {
  76.     /* Get an exclusive lock on it */
  77.     ObtainSemaphore(sigSem);
  78.  
  79.     /* And return true */
  80.     ret=1;
  81.     }
  82.  
  83.     /* All done */
  84.     Permit();
  85.     return ret;
  86.  
  87.     AROS_LIBFUNC_EXIT
  88. } /* AttemptSemaphore */
  89.  
  90.